<?php
/**
  * 系統名稱: Lotto 系統
  * 檔案說明: 專案管理-修改
  * $Author$
  * $Id$
  *
  */
set_time_limit(0);
//date_default_timezone_set("Etc/GMT+4");
$strWeb = $_SERVER[argv][1];
$isTimeLimit = $_SERVER[argv][2];

$arrNum[1] = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49";
$arrBType[1] = "4,5,6,7,8,9,10,11,12,13,14,17,18,19,20,21,22,23,24,25,26,27,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43";

$arrNum[2] = "";
$arrBType[2] = "51";
for($i = 52; $i <= 93; $i++)$arrBType[2] .= ",".$i;

$arrNum[3] = $arrNum[2];
$arrBType[3] = $arrBType[2];
$arrNum[6] = $arrNum[2];
$arrBType[6] = $arrBType[2];
$arrNum[7] = $arrNum[2];
$arrBType[7] = $arrBType[2];
$arrNum[8] = $arrNum[2];
$arrBType[8] = $arrBType[2];

$arrNum[4] = "";
$arrBType[4] = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22";

$arrNum[5] = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21";
$arrBType[5] = "1,2,3,4,5,6,7,8,9,10,11,12,13,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35";

$_SESSION["Admin_Info"] -> Account = "System";
$strLogError = $strWeb."Time: ".date("Y-m-d H:i:s")."\n";
$_isDBExist = "no";

$_SERVER["DOCUMENT_ROOT"] = "/home/share/www/".$strWeb."/secure";
include("/home/share/www/SourceSite-utf8/secure/config.inc.php");
include(__Root_Path."/config.inc.php");
include(__DBConnect_File);
if($_strLogErr != ""){
	@mysql_close($$_Conn);
	exit($strLogError.$_strLogErr);
}

include(__Common_Path."/Lotto.inc.php");
include(__Modules_Path."/Gamble.lib.php");

$NowTime = time();
foreach($_arrLotto as $intLID => $arrLo){
	$strLogError .= "LottoID: ".$intLID."\n";
	$arrGame = getNewGambleData($intLID, 0);
	if($arrGame === false){
		$strLogError .= $GLOBALS["errormessage"]."\n";
		$strLogError .= $GLOBALS["errorhidden"]."\n";
		continue;
	}elseif(sizeof($arrGame) == 0){
		$strLogError .= $strWeb." No Data!\n";
		continue;
	}

	$arrD = explode("-", $arrGame["GameDate"]);
	$arrT = explode(":", $arrGame["GameTime"]);
	$arrET = explode(":", $arrGame["EndGameTime"]);
	$arrSET = explode(":", $arrGame["EndGameTimeSN"]);
	$intT = mktime($arrT[0], $arrT[1], $arrT[2], $arrD[1], $arrD[2], $arrD[0]);
	$intET = mktime($arrET[0], $arrET[1], $arrET[2], $arrD[1], $arrD[2], $arrD[0]);
	$intSET = mktime($arrSET[0], $arrSET[1], $arrSET[2], $arrD[1], $arrD[2], $arrD[0]);
	if($intT < $intET && $arrT[0] < 12 && $arrET[0] > 12)$intET -= 86400; //若是跨 server 23:59 ~ 00:00
	if($intT < $intSET && $arrT[0] < 12 && $arrSET[0] > 12)$intSET -= 86400; //若是跨 server 23:59 ~ 00:00

	if($intT < $intET)$intET = $intT;
	//if($intT < $intSET)$intSET = $intT;

	if($arrLo["LType"] != 1)$isTimeLimit = 1;
	if($isTimeLimit == 0 || ($NowTime >= $intET && $NowTime <= ($intET + 180))){
		PMA_mysql_query("BEGIN", $_ConnMaster);
		if(!StopAllBetTodayGame($arrGame["ID"], $intLID, $arrBType[$intLID], $arrLo["LType"], 1, $arrNum[$intLID])){
			PMA_mysql_query("ROLLBACK", $_ConnMaster);
			$strLogError .= $GLOBALS["errormessage"]."\n";
			$strLogError .= $GLOBALS["errorhidden"]."\n";
		}else{
			PMA_mysql_query("COMMIT", $_ConnMaster);
			$strLogError .= "NN OK!\n\n";
		}
	}

	if($intLID == 1 && ($isTimeLimit == 0 || ($NowTime >= $intSET && $NowTime <= ($intSET + 180)))){
		PMA_mysql_query("BEGIN", $_ConnMaster);
		if(!StopAllBetTodayGame($arrGame["ID"], $intLID, "1,2,3,16", $arrLo["LType"], 1, $arrNum[$intLID])){
			PMA_mysql_query("ROLLBACK", $_ConnMaster);
			$strLogError .= $GLOBALS["errormessage"]."\n";
			$strLogError .= $GLOBALS["errorhidden"]."\n";
		}else{
			PMA_mysql_query("COMMIT", $_ConnMaster);
			$strLogError .= "SN OK!\n\n";
		}
	}
} //foreach($_arrLotto as $intLID => $arrLo){

@mysql_close($$_Conn);
$strLogError .= $strWeb."Time: ".date("Y-m-d H:i:s")." End\n\n";
exit($strLogError);
?>